package interviewpreparationkit.array

/**
 * [2D Array - DS](https://www.hackerrank.com/challenges/2d-array)
 */
// Complete the hourglassSum function below.
fun hourglassSum(arr: Array<Array<Int>>): Int {
    var max = Int.MIN_VALUE
    var current: Int
    for (i in 0 until 4) {
        for (j in 0 until 4) {
            current = 0
            for (k in 0 until 3) {
                current += arr[i][j + k] + arr[i + 2][j + k]
            }
            current += arr[i + 1][j + 1]
            if (current > max) {
                max = current
            }
        }
    }

    return max
}